// ActionScript file
package {
   import flash.display.Sprite;
   import flash.events.NetStatusEvent;
   import flash.events.SecurityErrorEvent;
   import flash.media.Video;
   import flash.net.NetConnection;
   import flash.net.NetStream;

   public class VideoExample extends Sprite {
       public  var videoUrl:String = "Video.flv";
       public  var connection:NetConnection;
       public  var stream:NetStream;

       public function VideoExample() {
           connection = new NetConnection();
           connection.addEventListener(NetStatusEvent.NET_STATUS,
netStatusHandler);
           connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
           connection.connect(null);
       }

       private function netStatusHandler(event:NetStatusEvent):void {
           switch (event.info.code) {
               case "NetConnection.Connect.Success":
                   connectStream();
                   break;
           }
       }

       private function securityErrorHandler(event:SecurityErrorEvent):void {
           trace("securityErrorHandler: " + event);
       }

       public function connectStream():void {
           var stream:NetStream = new NetStream(connection);
           var video:Video = new Video();
           video.attachNetStream(stream);
           stream.play(videoUrl);
           addChild(video);
       }
   }
}